
package com.lzb.compressmaster.dialog;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.AttachPopupView;
import com.lzb.compressmaster.R;

public class MoreDialog extends AttachPopupView implements View.OnClickListener {

    private boolean isShowRename;
    private boolean isShowEncrypt;
    private boolean isPrivacy;
    private TextView tvCopy;
    private TextView tvMove;
    private TextView tvRename;
    private TextView tvEncryption;
    private TextView tvViewPath;

    public MoreDialog(@NonNull Context context) {
        super(context);
    }

    public void setShowRename(boolean showRename) {
        isShowRename = showRename;
    }

    public void setShowEncrypt(boolean showEncrypt) {
        isShowEncrypt = showEncrypt;
    }

    public void setPrivacy(boolean privacy) {
        isPrivacy = privacy;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_more;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    protected void initView() {
        tvCopy = findViewById(R.id.tvCopy);
        tvMove = findViewById(R.id.tvMove);
        tvRename = findViewById(R.id.tvRename);
        tvEncryption = findViewById(R.id.tvEncryption);
        tvViewPath = findViewById(R.id.tvViewPath);

        tvCopy.setOnClickListener(this);
        tvMove.setOnClickListener(this);
        tvRename.setOnClickListener(this);
        tvEncryption.setOnClickListener(this);
        tvViewPath.setOnClickListener(this);

        if (isShowRename) {
            tvRename.setVisibility(View.VISIBLE);
            tvViewPath.setVisibility(View.VISIBLE);
        } else {
            tvRename.setVisibility(View.GONE);
            tvViewPath.setVisibility(View.GONE);
        }
        if (isShowEncrypt) {
            tvEncryption.setVisibility(View.VISIBLE);
        } else {
            tvEncryption.setVisibility(View.GONE);
        }
        if (isPrivacy) {
            tvEncryption.setText(getContext().getString(R.string.unencrypt));
        } else {
            tvEncryption.setText(getContext().getString(R.string.file_encryption));
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tvCopy) {
            dismiss();
            if (listener != null) {
                listener.clickCopy();
            }
        } else if (id == R.id.tvMove) {
            dismiss();
            if (listener != null) {
                listener.clickMove();
            }
        } else if (id == R.id.tvRename) {
            dismiss();
            if (listener != null) {
                listener.clickRename();
            }
        } else if (id == R.id.tvEncryption) {
            dismiss();
            if (listener != null) {
                listener.clickEncryption();
            }
        } else if (id == R.id.tvViewPath) {
            dismiss();
            if (listener != null) {
                listener.clickViewPath();
            }
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickCopy();

        void clickMove();

        void clickRename();

        void clickEncryption();

        void clickViewPath();
    }

}
